import 'package:app_30/json/base/json_convert_content.dart';

class BaseEntity<T> {
  BaseEntity(this.success, this.msg, this.data);

  bool? success;
  late String num;
  late String msg;
  String? jine;
  String? token;
  String? phonenumber;
  String? type;
  String? url;
  T? data;

  BaseEntity.fromJson(Map<String, dynamic> json) {
    String? successString = json['success'] as String?;
    if (successString == "true") {
      success = true;
    } else {
      success = false;
    }
    msg = json['msg'] as String;

    if (json['num'] != null) {
      num = json['num'] as String;
    }
    if (json['jine'] != null) {
      jine = json['jine'] as String;
    }
    if (json['token'] != null) {
      token = json['token'] as String;
    }
    if (json['phonenumber'] != null) {
      phonenumber = json['phonenumber'] as String;
    }
    if (json['type'] != null) {
      type = json['type'] as String;
    }
    if (json['url'] != null) {
      url = json['url'] as String;
    }
    if (json['data'] != null && json.containsKey('data')) {
      data = _generateOBJ<T>(json['data'] as Object);
    }
  }

  T _generateOBJ<O>(Object json) {
    if (T.toString() == 'String') {
      return json.toString() as T;
    } else if (T.toString() == 'Map<dynamic, dynamic>') {
      return json as T;
    } else {
      /// List类型数据由fromJsonAsT判断处理
      return JsonConvert.fromJsonAsT<T>(json);
    }
  }
}
